﻿using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using Framework.Library.Base.Base;
using Framework.Library.Base.Extensions;
using Framework.Library.Data.DAL;
using Framework.Library.Data.DAO;
using System.Linq;
using Framework.Library.Core.Utils.GlobalHelper;
using Framework.Library.Core.Utils;
using Framework.Library.Core.Utils.Images;
using Framework.Library.Data.DAL.JObject;

namespace Framework.Portal.Layouts.Client.Modules.Menu
{
    public partial class Tieudiem : BaseControl
    {
        public Tieudiem()
        {
        }

        public Tieudiem(JSection section)
        {
            if(!string.IsNullOrEmpty(section.parameter))
            {
                string[] arrParams = section.parameter.Split('&');
                if (arrParams.Length > 0)
                    menuId = Convert.ToInt32(arrParams[0].Split('=')[1]);
                if (arrParams.Length > 1)
                    catId = Convert.ToInt32(arrParams[1].Split('=')[1]);
            }
            MENUNAME = section.title;
        }
        public string MENUNAME = string.Empty;

        protected static int catId = 0;
        protected static int menuId = 0;
        protected static int curMenu = 0;
        protected int articleId = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int totalRecord;
                List<TeenioContent> lstContent = ManagerFactory.TeenioContentManager.GetList(catId, 2, 2, 0, 0, 1, out totalRecord);
                if (lstContent != null)
                {
                    pnlContent.Visible = true;
                    articleId = lstContent[0].CONTENT_ID;
                    if (!string.IsNullOrEmpty(lstContent[0].CONTENT_PREAVATAR))
                        imgAvatar.ImageUrl = ImagesUtils.GetImage(lstContent[0].CONTENT_PREAVATAR, 490, 215);
                    lblCreateDate.Text = DateTimeHelper.formatDateTime(lstContent[0].CONTENT_MODIFYDDATE);
                    lblTeaser.Text = ConvertUtility.ToSubString(lstContent[0].CONTENT_TEASER, 260);
                    hplTitle.Text = lstContent[0].CONTENT_HEADLINE;
                    hplTitle.NavigateUrl = cfg.ArticlePath(lstContent[0].CONTENT_PORTALID, lstContent[0].MENUID, lstContent[0].CONTENT_ID);
                    hplComment.NavigateUrl = cfg.ArticlePath(lstContent[0].CONTENT_PORTALID, lstContent[0].MENUID, lstContent[0].CONTENT_ID);
                }
            }
        }

    }
}